package vn.com.pavibook.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class DateUtils {
	private static final Logger LOGGER = Logger.getLogger(DateUtils.class);
	private static final String NORMAL_FORMAT = "yyyy-MM-dd";
	private static final String SIMPLE_FORMAT = "dd/MM/yyyy";
	
	public static String formatDateToString(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(NORMAL_FORMAT);
		return dateFormat.format(date);
	}

	public static String formatNormalDateString(String dateStr){
		SimpleDateFormat dateFormat = new SimpleDateFormat(SIMPLE_FORMAT);
		try {
			Date date = dateFormat.parse(dateStr);
			return formatDateToString(date);
		} catch (ParseException e) {
			LOGGER.error(e);
		} 
		return null;
	}
	
}
